package de.koller.oceanFramework.gl.util;

import java.nio.FloatBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;

public class Material {
	
	private float[] emission = new float[] { 0, 0, 0, 1 };
	private float[] diffuse = new float[] { 1f, 1f, 1f, 1 };
	private float[] ambient = new float[] { .5f, .5f, .5f, 1 };
	private float[] specular = new float[] { 0, 0, 0, 0 };
	private float shininess = 80;

	public void setMaterialGL() {
		FloatBuffer fb = BufferUtils.createFloatBuffer( 16 );
		
//		GL11.glColorMaterial( GL11.GL_FRONT_AND_BACK, GL11.GL_AMBIENT_AND_DIFFUSE );
//		GL11.glEnable( GL11.GL_COLOR_MATERIAL );
		
		fb.put( ambient ).flip();
		GL11.glMaterial( GL11.GL_FRONT_AND_BACK, GL11.GL_AMBIENT, fb );

		fb.put( diffuse ).flip();
		GL11.glMaterial( GL11.GL_FRONT_AND_BACK, GL11.GL_DIFFUSE, fb );
		
		fb.put( specular ).flip();
		GL11.glMaterial( GL11.GL_FRONT_AND_BACK, GL11.GL_SPECULAR, fb );
		
		fb.put( emission ).flip();
		GL11.glMaterial( GL11.GL_FRONT_AND_BACK, GL11.GL_EMISSION, fb );
		
		GL11.glMaterialf( GL11.GL_FRONT_AND_BACK, GL11.GL_SHININESS, shininess );
	}

	public void setMaterialGL(	float emissionR, float emissionG, float emissionB, float emissionA,
								float diffuseR,  float diffuseG,  float diffuseB,  float diffuseA,
								float ambientR,  float ambientG,  float ambientB,  float ambientA,
								float specularR, float specularG, float specularB, float specularA,
								float shininess ) {
		
		setEmission( new float[] { emissionR, emissionG, emissionB, emissionA } );
		setDiffuse(  new float[] { diffuseR,  diffuseG,  diffuseB,  diffuseA  } );
		setAmbient(  new float[] { ambientR,  ambientG,  ambientB,  ambientA  } );
		setSpecular( new float[] { specularR, specularG, specularB, specularA } );
		setShininess( shininess );
		
		this.setMaterialGL();
	}
	
	public float[] getAmbient() {
		return ambient;
	}

	public float[] getDiffuse() {
		return diffuse;
	}

	public float[] getEmission() {
		return emission;
	}

	public float getShininess() {
		return shininess;
	}

	public float[] getSpecular() {
		return specular;
	}

	public void setAmbient( float[] ambient ) {
		this.ambient = ambient;
	}

	public void setDiffuse( float[] diffuse ) {
		this.diffuse = diffuse;
	}

	public void setEmission( float[] emission ) {
		this.emission = emission;
	}

	public void setShininess( float shininess ) {
		this.shininess = shininess;
	}

	public void setSpecular( float[] specular ) {
		this.specular = specular;
	}
	
}
